import datamodel

import logging
import utils

from google.appengine.ext import db

class LinkConfig:
	def create(self, dispatcher):
		if not dispatcher.isAdmin:
			raise Exception("No Permissions")
		logging.info("create")  
		dispatcher.modelObject.put()
		return dispatcher.modelObject

	def update(self, dispatcher):
		if not dispatcher.isAdmin:
			raise Exception("No Permissions")
		logging.info("update")
		dispatcher.modelObject.put()
		return dispatcher.modelObject

	def delete(self, dispatcher):
		if not dispatcher.isAdmin:
			raise Exception("No Permissions")
		logging.info("delete")
		dispatcher.modelObject.delete();

	def get(self, dispatcher):
		logging.info("get all links")
		query = datamodel.LinkConfig().all()
		return query.fetch(100)

	def decode(self, decodeType, inputStr, inputObj, dispatcher):
		if inputObj == None:
			inputObj = datamodel.LinkConfig()
		return utils.GqlDecoder().decode(inputStr, inputObj)

	def encode(self, decodeType, outputObj, dispatcher):
		return utils.GqlEncoder().encode(outputObj)

